#!/bin/bash

if [ $# -lt 2 ]; then
    echo $0 ': too few arguments' 1>&2
    exit 1
fi

case $1 in
d) # dir
    if [ ! -d "$2" ]; then
        echo $0 ': not a dir' $2 1>&2
        exit 2
    fi
    cd $2
    fn=$(find . -maxdepth 1 -type d)
    for f in $fn; do
        if [ "$f" != '.' ]; then
            echo ${f#./}
        fi
    done
    cd - >/dev/null
    ;;
e) #exec
    fn=$(find $2 -name '*.cpp' | awk '{s=$1;sub(/^\.\//,"",s);sub(/\.cpp$/,"",s);print(s)}')
    for f in $fn; do
        echo "${f##*/},${f%/*}"
    done
    ;;
s) #src
    find $2 -name '*.cpp'
    ;;
*)
    echo $0 ': error opt' $1 1>&2
    exit 2
    ;;
esac
